package org.example;

import org.example.subsystem.SubSystem;

import java.util.HashMap;

public class Mediator {
    /**
     * 代码比较简单，就没有创建抽象层了
     */
    private HashMap<String,SubSystem> map = new HashMap<>();

    public void register(SubSystem system){
        if(!map.containsKey(system.getName())){
            map.put(system.getName(),system);
            system.setMediator(this);
            System.out.println(system.getName()+"已被注册");
        }
    }

    public void sendMessage( SubSystem to, String msg){
        System.out.println("向"+to.getName()+"发送了"+msg);
        to.receive(msg);
    }

}
